package com.zhc.dejingapi.job;

import com.zhc.dejingapi.service.upload.IGaogeErpBaseInfoUploadService;
import com.zhc.dejingapi.service.upload.IGaogeErpDataWithDetailUploadService;
import com.zhc.dejingapi.service.upload.IQingFlowDataDownloadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

@Slf4j
@Configuration
public class QingflowMoOrderUploadJob {

    public  static  boolean isRunning=false;
    private final JdbcTemplate mysqlJdbcTemplate;
    //private final IQingAppInfoService qqingAppInfoService;
    private final IGaogeErpBaseInfoUploadService gaogeErpBaseInfoUploadService;
    private final IQingFlowDataDownloadService qingFlowDataDownloadService;
    private final IGaogeErpDataWithDetailUploadService gaogeErpDataWithDetailUploadService;

    public QingflowMoOrderUploadJob(@Qualifier("mySqlJdbcTemplate")JdbcTemplate mysqlJdbcTemplate1,
                                    IGaogeErpBaseInfoUploadService qqingAppInfoService1,
                                    IQingFlowDataDownloadService qingFlowDataDownloadService1,
                                    IGaogeErpDataWithDetailUploadService gaogeErpDataWithDetailUploadService1) {
        this.mysqlJdbcTemplate = mysqlJdbcTemplate1;
        this.gaogeErpBaseInfoUploadService = qqingAppInfoService1;
        this.qingFlowDataDownloadService = qingFlowDataDownloadService1;
        this.gaogeErpDataWithDetailUploadService = gaogeErpDataWithDetailUploadService1;
    }

    public  void executeJob() {
        if (isRunning) {
            log.info("QingflowMoOrderUploadJob is running");
            try {
                Thread.sleep(1000 * 60 * 5);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return;
        }
        isRunning = true;

        int i = 0;
        if(i==1){
            try{
                qingFlowDataDownloadService.downPRoutingData();

            }
            catch (Exception e){

            }
            try{
                qingFlowDataDownloadService.downProductExtenData();

            }
            catch (Exception e){

            }
            try{

                qingFlowDataDownloadService.downProductPicSop();
            }
            catch (Exception e){

            }
            try {
                gaogeErpDataWithDetailUploadService.uploadBomWork();


            } catch (Exception e) {
                e.printStackTrace();
                log.error("ERPProdClassToQingJob error", e);
            }
            try {
                gaogeErpDataWithDetailUploadService.QueryBomWorkActionResult();


            } catch (Exception e) {
                e.printStackTrace();
                log.error("ERPProdClassToQingJob error", e);
            }
        }


        isRunning = false;
    }
}
